package com.zbs.framework.common.enums;

import com.alibaba.fastjson.serializer.JSONSerializer;
import com.alibaba.fastjson.serializer.ObjectSerializer;

import java.io.IOException;
import java.lang.reflect.Type;

/**
 * @author: Zbs
 * @createTime: 2021/3/1 16:53
 */
public class EnumSerializer implements ObjectSerializer {
    @Override
    public void write(JSONSerializer jsonSerializer, Object o, Object o1, Type type, int i) throws IOException {
        if (o instanceof BaseEnum) {
            BaseEnum baseEnum = (BaseEnum) o;
            jsonSerializer.out.write(baseEnum.getCode().toString());
        } else {
            jsonSerializer.out.writeString(String.valueOf(o));
        }

    }
}
